#! /bin/bash
# 获取当前目录
CRTDIR=$(pwd)
# echo $CRTDIR

# 检查否安装Jmeter
if [ ! -d apache-jmeter-5.3 ]
then
	# 下载Jmeter的tar包:tar -zxvf jdk-8u181-linux-x64.tar.gz:
	wget -c https://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-5.3.tgz
	tar -xf apache-jmeter-5.3.tgz
fi

# 获取本地IP：
local_ip=$(/sbin/ifconfig -a |grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")

# 添加临时环境变量
export PATH=$PATH:$CRTDIR/apache-jmeter-5.3/bin

# 配置jmeter.properties
echo "执行slaver($local_ip)配置:"
cd $CRTDIR/apache-jmeter-5.3/bin
echo "*******************************"

# 配置server_port
sed -i 's/\#server_port=.*/server_port=1099/g' jmeter.properties |grep server_port=
egrep '^server_port=1099' jmeter.properties

# 配置server.rmi.ssl.disable=true,去掉ssl认证
sed -i 's/\#server\.rmi\.ssl\.disable=.*/server\.rmi\.ssl\.disable=true/g' jmeter.properties |grep server\.rmi\.ssl\.disable=
egrep '^server\.rmi\.ssl\.disable=' jmeter.properties

# 配置sampleresult.default.encoding=utf-8
sed -i 's/\#sampleresult\.default\.encoding=.*/sampleresult\.default\.encoding=utf-8/g' jmeter.properties |grep sampleresult\.default\.encoding=
egrep '^sampleresult\.default\.encoding=' jmeter.properties


# 启动服务jmeter-server
./jmeter-server -Djava.rmi.server.hostname=$local_ip
#netstat -plunt |grep 1099